#ifndef DockWidgetTabH
#define DockWidgetTabH
/*******************************************************************************
** Qt Advanced Docking System
** Copyright (C) 2017 Uwe Kindler
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; either
** version 2.1 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with this library; If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/


//============================================================================
/// \file   DockWidgetTab.h
/// \author Uwe Kindler
/// \date   27.02.2017
/// \brief  Declaration of CDockWidgetTab class
//============================================================================


//============================================================================
//                                   INCLUDES
//============================================================================
#include <QFrame>
#include <QSize>

#include "ads_globals.h"

namespace ads
{
class CDockWidget;
class CDockAreaWidget;
struct DockWidgetTabPrivate;
class CDockManager;

/**
 * 一个显示标题和图标的停靠窗口标签。
 * 停靠窗口标签显示在停靠区域标题栏上，用于在选项卡式停靠窗口之间切换。
 */
class ADS_EXPORT CDockWidgetTab : public QFrame
{
    Q_OBJECT
    Q_PROPERTY(bool activeTab READ isActiveTab WRITE setActiveTab NOTIFY activeTabChanged)
    Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)

// 私有数据（pimpl）
private:
    DockWidgetTabPrivate* d;
    
    // 友元类
    friend struct DockWidgetTabPrivate;
    friend class CDockWidget;
    friend class CDockManager;
    friend class CAutoHideDockContainer;
    
    // 槽函数
private Q_SLOTS:
    // 分离 Dock Widget
    void detachDockWidget();
    
    // 自动隐藏 Dock Widget
    void autoHideDockWidget();
    
    // 自动隐藏到操作被点击时的槽函数
    void onAutoHideToActionClicked();
    
protected:
    // 事件处理函数
    // 鼠标按下事件
    virtual void mousePressEvent(QMouseEvent* ev) override;
    
    // 鼠标释放事件
    virtual void mouseReleaseEvent(QMouseEvent* ev) override;
    
    // 鼠标移动事件
    virtual void mouseMoveEvent(QMouseEvent* ev) override;
    
    // 上下文菜单事件
    virtual void contextMenuEvent(QContextMenuEvent* ev) override;
    
    // 双击事件
    virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
    
public:
    // 基类
    using Super = QFrame;
    
    // 构造函数
    CDockWidgetTab(CDockWidget* DockWidget, QWidget* parent = 0);
    
    // 析构函数
    virtual ~CDockWidgetTab();
    
    // 检查是否为活动标签
    bool isActiveTab() const;
    
    // 设置为活动标签
    void setActiveTab(bool active);
    
    // 设置 Dock Area Widget
    void setDockAreaWidget(CDockAreaWidget* DockArea);

	/**
 * 返回此标题栏所属的停靠区域小部件。
 * \return 如果拥有此标题栏小部件的停靠小部件尚未添加到任何停靠区域，则此函数返回0。
 */
CDockAreaWidget* dockAreaWidget() const;

/**
 * 返回此标题小部件所属的停靠小部件
 */
CDockWidget* dockWidget() const;

/**
 * 设置在标题栏中显示的图标
 */
void setIcon(const QIcon& Icon);

/**
 * 返回图标
 */
const QIcon& icon() const;

/**
 * 返回选项卡文本
 */
QString text() const;

/**
 * 设置选项卡文本
 */
void setText(const QString& title);

/**
 * 如果选项卡的标题被省略，则返回true
 */
bool isTitleElided() const;

/**
 * 此函数返回true，如果分配的停靠小部件可关闭
 */
bool isClosable() const;

/**
 * 跟踪事件ToolTipChange并设置子ToolTip
 */
virtual bool event(QEvent *e) override;

/**
 * 设置文本省略模式
 */
void setElideMode(Qt::TextElideMode mode);

/**
 * 如果属性发生更改，则更新样式表样式
 */
void updateStyle();

/**
 * 返回图标大小。
 * 如果没有设置显式图标大小，该函数将返回无效的QSize
 */
QSize iconSize() const;

/**
 * 设置显式图标大小。
 * 如果没有显式设置图标大小，则选项卡根据样式设置图标大小
 */
void setIconSize(const QSize& Size);

public Q_SLOTS:
virtual void setVisible(bool visible) override;

Q_SIGNALS:
void activeTabChanged();
void clicked();
void closeRequested();
void closeOtherTabsRequested();
void moved(const QPoint& GlobalPos);
void elidedChanged(bool elided);
}; // class DockWidgetTab
}
 // namespace ads
//-----------------------------------------------------------------------------
#endif // DockWidgetTabH
